package com.lushu.chapitre1.net.services
{
	import com.lushu.log.Logger;
	import com.lushu.net.php.RemotingService;
	import com.lushu.utils.MD5;
	
	import flash.net.Responder;
	
	import flexunit.framework.Assert;
	
	import org.flexunit.async.Async;
	
	public class UserServiceTest extends BaseServiceTest
	{		
		[BeforeClass]
		public static function setUpBeforeClass():void
		{
			_remotingService = new RemotingService("http://localhost:8400/Chapitre1_DataService/messagebroker/amf");
			_logger = new Logger();
		}
		
		[AfterClass]
		public static function tearDownAfterClass():void
		{
			_remotingService = null;
			_logger = null;
		}
		
		[Test(async,timeout="3000",order="1")] 
		public function testLogonUser():void
		{
			var userName : String = "kanegank";
			var password : String = MD5.hash("bonnie");
			var serviceResponder : Responder = Async.asyncNativeResponder(this, onLogonUserResult, onLogonUserFault, 3000, null, onDefaultTimeout);
			UserService.logonUserResponder(serviceResponder, userName, password);
		}
		
		[Test(async,timeout="3000",order="2")] 
		public function testLogonUser2():void
		{
			RemotingService.instance.login("nioTest", "test");
			var userName : String = "kanegank";
			var password : String = MD5.hash("bonnie");
			var serviceResponder : Responder = Async.asyncNativeResponder(this, onLogonUserResult, onLogonUserFault, 3000, null, onDefaultTimeout);
			UserService.logonUserResponder(serviceResponder, userName, password);
		}
		
		[Test(async,timeout="3000",order="3")] 
		public function testLogonUser3():void
		{
			var userName : String = "kanegank";
			var password : String = MD5.hash("bonnie");
			var serviceResponder : Responder = Async.asyncNativeResponder(this, onLogonUserResult, onLogonUserFault, 3000, null, onDefaultTimeout);
			UserService.logonUserResponder(serviceResponder, userName, password);
		}
		
		private function onLogonUserResult(data :*, data2 : * = null, data3 : * = null) : void
		{
			Assert.assertNotNull(data, "UserFarmService.getFarm :: The returned data is null");
		}
		
		private function onLogonUserFault(data : Object) : void
		{
			Assert.fail("UserFarmService.getFarm :: Error while retrieving the farm data"); 
		}
	}
}